<?php

namespace App\Http\Controllers;

use App\Notifications\RegistMailNotify;
use App\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
    //
    public function show(){
        //加载模板
        return view('user.show');
    }

    /**
     * 完成账号激活方法
     * @param $token
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function jihuo($token){
        //通过token值找到当前用户数据，将账号状态改为1
        $user = User::where('email_token',$token)->first();
        //开始判断
        if($user){
            $user->status = 1;
            $user->save();
            //设置闪存信息并返回
            session()->flash('success','恭喜账号激活成功！！！');
            return redirect('/');
        }
    }

    /**
     * 重新发送激活邮件方法
     */
    public function sendMail(){
        //获取当前登录的用户数据
        $user = auth()->user();
        \Notification::send($user,new RegistMailNotify($user));
        session()->flash('success','邮件已经重新发送至你的邮箱,请查收');
        return back();
    }
}
